#ifndef __UART3_H__
#define __UART3_H__
#include "stdio.h"	
#include "stm32f10x.h" 
#include "rtos.h"
#include "uartcommon.h"

#define UART3_TXBUFF_SIZE   200
#define UART3_RXBUFF_SIZE   200
#define UART3_RX_QUEUE_LEN  2
#define UART3_TX_INTERVAL 20    //ms
#define UART3_RX_INTERVAL 8  //ms



#ifndef TMDLY_BIT4
#define TMDLY_BIT4
#define UART3RXCTRBIT			0x010
#define UART3RXCTRTM			Timer3Ctr.time[4]
#define SETUART3RXDLY()		{TIM_ITConfig(TIM3,TIM_IT_Update,DISABLE);\
														Timer3Ctr.devbit |= UART3RXCTRBIT;\
														UART3RXCTRTM = (u32)UART3_RX_INTERVAL;\
														TIM_ITConfig(TIM3,TIM_IT_Update,ENABLE);\
													}
#define RESETUART3RXDLY()	{DISABLE_INT();\
													Timer3Ctr.devbit &= ~UART3RXCTRBIT;\
														UART3RXCTRTM = 0;\
														ENABLE_INT();}
#else
#error TMDLY_BIT4 has been defined!
#endif	//TMDLY_BIT4


#ifndef TMDLY_BIT5
#define TMDLY_BIT5
#define UART3TXCTRBIT			0x020
#define UART3TXCTRTM			Timer3Ctr.time[5]
#define SETUART3TXDLY()		{TIM_ITConfig(TIM3,TIM_IT_Update,DISABLE);\
														Timer3Ctr.devbit |= UART3TXCTRBIT;\
														UART3TXCTRTM = (u32)UART3_TX_INTERVAL;\
														TIM_ITConfig(TIM3,TIM_IT_Update,ENABLE);\
													}
#define RESETUART3TXDLY()	{DISABLE_INT();\
													Timer3Ctr.devbit &= ~UART3TXCTRBIT;\
													UART3TXCTRTM = 0;\
													ENABLE_INT();}
#else
#error TMDLY_BIT5 has been defined!
#endif	//TMDLY_BIT5




extern UARTSTRUCT MyUart3;
extern SemaphoreHandle_t  Binary_Uart3;
void Uart3_Init(u32 bound);






static void Uart3_TxDMAConfig(void);
static void Uart3TXDMAStart(u8 *senddata,u16 datalen);
static void Uart3_PutC(u8 udata);
static void Uart3_PutStrlen(u8 *senddata,u16 datalen);
static void Uart3_Printf(char* fmt,...) ;
static u8 Uart3_GetOneRxPkg(UART_RXINFO *pkginfo,u32 timetowait_ms);
static void Uart3_ReleaseOneRxPkg(UART_RXINFO *pkginfo);
static void Uart3_Var_Init(void);
static void Uart3_SendBeforCallBack(void);
static void Uart3_SendOverCallBack(void);
static void Uart3_StoreOneRxPkg(void);
static u8 Uart3_GetOneRxPkg(UART_RXINFO *pkginfo,u32 timetowait_ms);
static void Uart3_ReleaseOneRxPkg(UART_RXINFO *pkginfo);
static void Uart3_ReleaseAllRxPkg(void);
#endif


